.class public Lcom/sponsorpay/sdk/android/SponsorPay;
.super Ljava/lang/Object;
.source "SponsorPay.java"


# static fields
.field public static final BUGFIX_RELEASE_NUMBER:I = 0x1

.field protected static INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay; = null

.field public static final MAJOR_RELEASE_NUMBER:I = 0x4

.field public static final MINOR_RELEASE_NUMBER:I

.field public static final RELEASE_VERSION_STRING:Ljava/lang/String;


# instance fields
.field private currentCredentials:Ljava/lang/String;

.field private tokensMap:Ljava/util/HashMap;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/HashMap",
            "<",
            "Ljava/lang/String;",
            "Lcom/sponsorpay/sdk/android/credentials/SPCredentials;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method static constructor <clinit>()V
    .locals 5

    .prologue
    const/4 v4, 0x1

    const/4 v3, 0x0

    .line 35
    const-string v0, "%d.%d.%d"

    const/4 v1, 0x3

    new-array v1, v1, [Ljava/lang/Object;

    .line 36
    const/4 v2, 0x4

    invoke-static {v2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v2

    aput-object v2, v1, v3

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v2

    aput-object v2, v1, v4

    const/4 v2, 0x2

    invoke-static {v4}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    aput-object v3, v1, v2

    .line 35
    invoke-static {v0, v1}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v0

    sput-object v0, Lcom/sponsorpay/sdk/android/SponsorPay;->RELEASE_VERSION_STRING:Ljava/lang/String;

    .line 38
    new-instance v0, Lcom/sponsorpay/sdk/android/SponsorPay;

    invoke-direct {v0}, Lcom/sponsorpay/sdk/android/SponsorPay;-><init>()V

    sput-object v0, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    return-void
.end method

.method protected constructor <init>()V
    .locals 1

    .prologue
    .line 44
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 40
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lcom/sponsorpay/sdk/android/SponsorPay;->tokensMap:Ljava/util/HashMap;

    .line 45
    return-void
.end method

.method public static getAllCredentials()Ljava/util/Set;
    .locals 1
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/Set",
            "<",
            "Ljava/lang/String;",
            ">;"
        }
    .end annotation

    .prologue
    .line 138
    sget-object v0, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    iget-object v0, v0, Lcom/sponsorpay/sdk/android/SponsorPay;->tokensMap:Ljava/util/HashMap;

    invoke-virtual {v0}, Ljava/util/HashMap;->keySet()Ljava/util/Set;

    move-result-object v0

    return-object v0
.end method

.method public static getCredentials(Ljava/lang/String;)Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    .locals 1
    .parameter "credentialsToken"

    .prologue
    .line 94
    sget-object v0, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    invoke-direct {v0, p0}, Lcom/sponsorpay/sdk/android/SponsorPay;->getCredentialsFromToken(Ljava/lang/String;)Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    move-result-object v0

    return-object v0
.end method

.method private getCredentialsFromToken(Ljava/lang/String;)Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    .locals 4
    .parameter "token"

    .prologue
    .line 48
    iget-object v1, p0, Lcom/sponsorpay/sdk/android/SponsorPay;->tokensMap:Ljava/util/HashMap;

    invoke-virtual {v1, p1}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    .line 49
    .local v0, credendials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    if-nez v0, :cond_0

    .line 50
    new-instance v1, Ljava/lang/RuntimeException;

    new-instance v2, Ljava/lang/StringBuilder;

    const-string v3, "There are no credentials identified by "

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v2, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    .line 51
    const-string v3, "\nYou have to execute SponsorPay.start method first."

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 50
    invoke-direct {v1, v2}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 53
    :cond_0
    return-object v0
.end method

.method public static getCurrentCredentials()Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    .locals 2

    .prologue
    .line 78
    sget-object v0, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    iget-object v0, v0, Lcom/sponsorpay/sdk/android/SponsorPay;->currentCredentials:Ljava/lang/String;

    invoke-static {v0}, Lcom/sponsorpay/sdk/android/utils/StringUtils;->nullOrEmpty(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 79
    new-instance v0, Ljava/lang/RuntimeException;

    const-string v1, "No credentials object was created yet.\nYou have to execute SponsorPay.start method first."

    invoke-direct {v0, v1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v0

    .line 82
    :cond_0
    sget-object v0, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    sget-object v1, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    iget-object v1, v1, Lcom/sponsorpay/sdk/android/SponsorPay;->currentCredentials:Ljava/lang/String;

    invoke-direct {v0, v1}, Lcom/sponsorpay/sdk/android/SponsorPay;->getCredentialsFromToken(Ljava/lang/String;)Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    move-result-object v0

    return-object v0
.end method

.method public static start(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/content/Context;)Ljava/lang/String;
    .locals 3
    .parameter "appId"
    .parameter "userId"
    .parameter "securityToken"
    .parameter "context"

    .prologue
    .line 123
    new-instance v0, Ljava/util/HashSet;

    invoke-static {}, Lcom/sponsorpay/sdk/android/SponsorPay;->getAllCredentials()Ljava/util/Set;

    move-result-object v2

    invoke-direct {v0, v2}, Ljava/util/HashSet;-><init>(Ljava/util/Collection;)V

    .line 124
    .local v0, credentials:Ljava/util/Set;,"Ljava/util/Set<Ljava/lang/String;>;"
    sget-object v2, Lcom/sponsorpay/sdk/android/SponsorPay;->INSTANCE:Lcom/sponsorpay/sdk/android/SponsorPay;

    invoke-virtual {v2, p0, p1, p2, p3}, Lcom/sponsorpay/sdk/android/SponsorPay;->getCredentialsToken(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/content/Context;)Ljava/lang/String;

    move-result-object v1

    .line 126
    .local v1, credentialsToken:Ljava/lang/String;
    invoke-interface {v0, v1}, Ljava/util/Set;->contains(Ljava/lang/Object;)Z

    move-result v2

    if-nez v2, :cond_0

    .line 127
    invoke-static {p3}, Lcom/sponsorpay/sdk/android/advertiser/SponsorPayAdvertiser;->register(Landroid/content/Context;)V

    .line 129
    :cond_0
    return-object v1
.end method


# virtual methods
.method protected getCredentialsToken(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/content/Context;)Ljava/lang/String;
    .locals 3
    .parameter "appId"
    .parameter "userId"
    .parameter "securityToken"
    .parameter "context"

    .prologue
    .line 60
    iget-object v1, p0, Lcom/sponsorpay/sdk/android/SponsorPay;->tokensMap:Ljava/util/HashMap;

    invoke-static {p1, p2}, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;->getCredentialsToken(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/util/HashMap;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    .line 62
    .local v0, credentials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    if-nez v0, :cond_1

    .line 63
    new-instance v0, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;

    .end local v0           #credentials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    invoke-direct {v0, p1, p2, p3, p4}, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/content/Context;)V

    .line 64
    .restart local v0       #credentials:Lcom/sponsorpay/sdk/android/credentials/SPCredentials;
    iget-object v1, p0, Lcom/sponsorpay/sdk/android/SponsorPay;->tokensMap:Ljava/util/HashMap;

    invoke-virtual {v0}, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;->getCredentialsToken()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2, v0}, Ljava/util/HashMap;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 68
    :cond_0
    :goto_0
    invoke-virtual {v0}, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;->getCredentialsToken()Ljava/lang/String;

    move-result-object v1

    iput-object v1, p0, Lcom/sponsorpay/sdk/android/SponsorPay;->currentCredentials:Ljava/lang/String;

    .line 69
    iget-object v1, p0, Lcom/sponsorpay/sdk/android/SponsorPay;->currentCredentials:Ljava/lang/String;

    return-object v1

    .line 65
    :cond_1
    invoke-static {p3}, Lcom/sponsorpay/sdk/android/utils/StringUtils;->notNullNorEmpty(Ljava/lang/String;)Z

    move-result v1

    if-eqz v1, :cond_0

    .line 66
    invoke-virtual {v0, p3}, Lcom/sponsorpay/sdk/android/credentials/SPCredentials;->setSecurityToken(Ljava/lang/String;)V

    goto :goto_0
.end method
